package hintEmCimaDoMetodo;

import java.util.Iterator;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.IEditorPart;

public class JavaAnnotationHover implements IAnnotationHover, org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover 
{

    /* (non-Javadoc)
     * Method declared on IAnnotationHover
     */
    public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) 
    {
    	Iterator<Annotation> iteradorAnnotations = sourceViewer.getAnnotationModel().getAnnotationIterator();
    	while(iteradorAnnotations.hasNext() == true)
    	{
    		Annotation anotacao = iteradorAnnotations.next();
    		System.out.println("anotacao obtida:" + anotacao.getText());
    	}
            /*IDocument document= sourceViewer.getDocument();

            try {
                    IRegion info= document.getLineInformation(lineNumber);
                    return document.get(info.getOffset(), info.getLength());
            } catch (BadLocationException x) {
            }*/

            return null;
    }

	@Override
	public String getHoverInfo(ITextViewer arg0, IRegion arg1) 
	{
		try
		{
			ISourceViewer source = (ISourceViewer) arg0;
			int indicePorOndeComecaSelecionado = arg1.getOffset();
			IDocument document = arg0.getDocument();
			int numLinhaDoSelecionado = document.getLineOfOffset(indicePorOndeComecaSelecionado); 
			 
			return this.getHoverInfo(source, numLinhaDoSelecionado);
		}
		catch(BadLocationException exc)
		{
			exc.printStackTrace();
			return null;
		}
		
	}

	@Override
	public IRegion getHoverRegion(ITextViewer arg0, int arg1) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setEditor(IEditorPart arg0) {
		// TODO Auto-generated method stub
		
	}
}